package com.xmcowell.sportpacemaster.utils;

import android.os.Handler;

import com.xmcowell.sportpacemaster.config.Contents;

/**
 * 计时器
 * Created by Administrator on 2017/6/9 0009.
 */

public class TimeThread implements Runnable {
    private final int rushDaly = 1000;//刷新率，1s1次
    private Boolean isStop = true;
    private Boolean isFinish = false;
    private Handler mHandler;
    private int runTimes = 0;

    public TimeThread(Handler mHandler) {
        this.mHandler = mHandler;
    }

    @Override
    public void run() {
        while (!isFinish) {
            try {
                Thread.sleep(rushDaly);
            } catch (InterruptedException e) {
                e.printStackTrace();
                break;
            }
                runTimes += 1;
                mHandler.sendEmptyMessage(Contents.TIME_THREAD_REFLASH);
        }
    }

    public void stop() {
        isStop = true;
    }

    public void start() {
        isStop = false;
        isFinish = false;
        runTimes = 0;
    }

    public void finish() {
        isFinish = true;
        runTimes = 0;
    }

    public int getTime() {
        return runTimes;
    }

    public boolean isStop() {
        return isStop;
    }
}
